Function.prototype.hyapply = function (thisArg, argArray) {
  // 获取要执行的函数
  var fn = this;
  // 处理绑定的thisArg
  thisArg =
    thisArg !== null && thisArg !== undefined ? Object(thisArg) : window;

  // 执行函数
  thisArg.fn = fn;
  var result = null;
  // if (!argArray) {
  //   result = thisArg.fn();
  // } else {
  //   result = thisArg.fn(...argArray);
  // }
  // argArray = argArray ? argArray : [];
  argArray = argArray || [];
  result = thisArg.fn(...argArray);
  delete thisArg.fn;

  return result;
};

function sum(num1, num2) {
  console.log("sum被调用", this, num1, num2);
  return num1 + num2;
}

var res = sum.hyapply({ name: "frank" }, [20, 30]);
console.log(res);
